package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.login.TsLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.user.service.UserListenProcessService;
import com.atguigu.tingshu.vo.user.UserListenProcessVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Map;

@Tag(name = "用户声音播放进度管理接口")
@RestController
@RequestMapping("api/user/userListenProcess")
@SuppressWarnings({"all"})
public class UserListenProcessApiController {

	@Autowired
	private UserListenProcessService userListenProcessService;

	@TsLogin
	@Operation(summary = "获取上次声音跳出的时间")
    @GetMapping("/getTrackBreakSecond/{trackId}")
	public Result getTrackBreakSecond(@PathVariable Long trackId){
		//获取用户id
		Long userId = AuthContextHolder.getUserId();
		//根据用户id判断mongoDB中是否有播放记录
		BigDecimal breakSecond = userListenProcessService.getTrackBreakSecond(trackId,userId);
		return Result.ok(breakSecond);
	}

	@TsLogin
	@Operation(summary = "更新播放进度")
	@PostMapping("/updateListenProcess")
	public Result updateListenProcess(@RequestBody UserListenProcessVo userListenProcessVo){
		//获取用户id
		Long userId = AuthContextHolder.getUserId();
		//调用服务层方法
		userListenProcessService.updateListenProcess(userListenProcessVo,userId);
		return Result.ok();
	}

	@Operation(summary = "获取最近播放的声音")
	@GetMapping("/getLatelyTrack")
	public Result getLatelyTrack(){
		Long userId = AuthContextHolder.getUserId();
		Map<String,Object> map = userListenProcessService.getLatelyTrack(userId);
		return Result.ok(map);
	}

}

